package com.yixin.hospital.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yixin.hospital.common.ApiResult;
import com.yixin.hospital.entity.domain.Card;
import com.yixin.hospital.entity.dto.req.card.CardAddReqDTO;
import com.yixin.hospital.entity.dto.req.card.CardEditReqDTO;
import com.yixin.hospital.entity.vo.CardVo;
import com.yixin.hospital.service.CardService;
import com.yixin.hospital.mapper.CardMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【card(卡表)】的数据库操作Service实现
* @createDate 2024-10-09 16:54:13
*/
@Service
public class CardServiceImpl extends ServiceImpl<CardMapper, Card>
    implements CardService{

    @Override
    public ApiResult<List<CardVo>> allList() {
        List<Card> list = this.list();
        List<CardVo> cardVos = BeanUtil.copyToList(list, CardVo.class);
        for (CardVo cardVo : cardVos) {
            cardVo.setCardId(cardVo.getId());
            cardVo.setCardName(cardVo.getName());
        }
        return ApiResult.success(cardVos);
    }

    @Override
    public ApiResult add(CardAddReqDTO cardAddReqDTO, String userName) {
        Card card = new Card();
        BeanUtils.copyProperties(cardAddReqDTO, card);
        card.setCreatedBy(userName);
        card.setUpdatedBy(userName);
        this.save(card);
        return ApiResult.success();
    }

    @Override
    public ApiResult<?> edit(CardEditReqDTO cardEditReqDTO, String userName) {
        Card card = new Card();
        BeanUtils.copyProperties(cardEditReqDTO, card);
        card.setUpdatedBy(userName);
        this.updateById(card);
        return ApiResult.success();
    }
}




